package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.mapper.TravelMapper;
import cn.wolfcode.trip.base.query.TravelCommendQuery;
import cn.wolfcode.trip.base.query.TravelQuery;
import cn.wolfcode.trip.base.service.IRegionService;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by 13925 on 2018/10/28.
 */

/**
 * 地区服务实现类
 */
@Service
public class TravelCommendServiceImpl implements ITravelCommendService {

    @Autowired
    private TravelCommendMapper travelCommendMapper;

    @Override
    public PageInfo query(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<TravelCommend> list = travelCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(TravelCommend travelCommend) {
        if (travelCommend.getId() != null) {
            travelCommendMapper.updateByPrimaryKey(travelCommend);
        } else {
            travelCommendMapper.insert(travelCommend);
        }
    }

    @Override
    public PageInfo queryForApp(TravelCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        //为了适应app端渲染需求而改造的数据封装
        List<Map<String, Object>> list = travelCommendMapper.selectForApp(qo);
        return new PageInfo(list);
    }

}
